/*
 * @Author: wenhui wenhui@wenhuiweb.cn
 * @Date: 2024-08-26
 * @Description: 用户管理
 */
import request from '@/utils/request';

// 用户列表
export const getUserList = data => {
  const { page = 1,limit, ...otherPames } = data;

  const parms = [];
  for (let key in otherPames) {
    if (otherPames[key]) {
      parms.push(`${key}=${otherPames[key]}&`);
    }
  }

  const url = `?${parms.join('&')}}`;
  // return request.get(`/admin/user/${page}${url}`, data);
  return request.get(`/admin/getUserList?page=${page}&limit=${limit}`, data);
}


// 增加用户
export const addUser = data => {
  return request.post('/admin/setUserInfo', data);
}


// 修改用户
export const updateUser = data => {
  const { id } = data;
  return request.put(`/admin/setUserInfo`, data);
}


// 修改用户状态
export const updateUserStatus = data => {
  const { id } = data;
  return request.put(`/admin/setUserInfo/update_status/${id}`, data);
}

// 删除用户
export const deleteUser = data => {
  const { id } = data;
  return request.delete(`/admin/setUserInfo?id=${id}`);
}




// 会员等级列表
export const getLevelList = data => {
  const { page, limit } = data;
  return request.get(`/admin/getUserLevel`, {
    params: {page, limit}
  });
}


// 增加会员等级
export const addLevel = data => {
  return request.post('/admin/setUserLevel', data);
}


// 修改会员等级
export const updateLevel = data => {
  return request({
    url: `/admin/setUserLevel`,
    method: 'put',
    data
  });
}


// 修改会员等级状态
export const updateLevelStatus = data => {
  const { id } = data;
  return request.put(`/admin/setUserLevel/update_status/${id}`, data);
}


// 删除会员等级
export const deleteLevel = data => {
  const { id } = data;
  return request.delete(`/admin/setUserLevel?id=${id}`);
}

